"""
@name : 面向对象
@author : shiyaling
@projectname : xsfh
"""
import random
class Role(object):
    def __init__(self,name,sex,cloth,blood=100):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.cloth = cloth
        self.room = None

    def attact(self,other):
        if self == other:
            print("不能攻击自己")
        else:
            if self.room == other.room:
                if self.blood <= 0:
                    print("您的血量低于0，不能进行攻击")
                else:
                    if self.cloth == "y":
                        lost_blood = 5
                        print(f"{other.name}有装备")
                    else:
                        lost_blood = 10
                        print(f"{other.name}没有装备")
                other.blood = other.blood - lost_blood
                print(f"{self.name}攻击了{other.name}")
                print(f"{other.name}减少了{lost_blood}血量，剩余{other.blood}")
                if other.blood <= 0:
                    print(f"{other.name}已阵亡,游戏结束")
                    exit()
            else:
                print("不在同一房间不能进行攻击")


class Room(object):
    def __init__(self,number):
        self.number = number
        self.member_list = []
    def add_member(self,role):
        if role.room == None:
            if len(self.member_list) <= 1:
                self.member_list.append(role)
                role.room = self
            print(f"{role.name}成功加入{self.number}房间")
        else:
            print(f"{role.name}已加入{role.room.number}房间")


print("#############"
      "1、创建角色"
      "2、创建房间"
      "3、加入房间"
      "4、开始战斗"
      "5、退出"
      "#############")
roles = {}
rooms = {}
while True:
    choose = int(input("请输入你要进行的操作："))
    if 1 <= choose <= 5:
        if choose == 1:
            name = input("请输入角色的姓名：")
            sex = input("请输入角色的性别：")
            cloth = input("请输入角色是否有装备，有输入y，没有输入n：")
            roles[name] = Role(name,sex,cloth)
        elif choose == 2:
            room = input("请输入你所创建的房间号：")
            rooms[room] = Room(room)
        elif choose == 3:
            print(f"当前有{roles.keys()}")
            print(f"当前有{rooms.keys()}")
            role_name = input("请输入你要加入的角色：")
            room_number = input("请输入你要加入的房间:")
            rooms[room_number].add_member(roles[role_name])
        elif choose == 4:
            while True:
                enter = random.choice([0,1])
                if enter == 0:
                    rooms[room_number].member_list[0].attact(rooms[room_number].member_list[1])
                else:
                    rooms[room_number].member_list[1].attact(rooms[room_number].member_list[0])
        else:
            exit()
    else:
        print("输入错误，请输入正确的操作！")









